package com.it.modul;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @Author 15593
 * @create 2021/12/30 18:12
 */
public class DishApp {

    static List<Dish> listDish = new ArrayList<Dish>();
    static List<Dish> listDish2 = new ArrayList<Dish>();

    public static void main(String[] args) throws InterruptedException {
        initDish();
        Scanner scanner = new Scanner(System.in);
        X1:while (true) {
            showMenu();
            int nextInt = scanner.nextInt();
            switch (nextInt) {
                case 1:
                    //展示菜单给用户
                    X2:while (true) {
                        showMenuDish();
                        int id = scanner.nextInt();
                        if (id == 0) {
                            System.out.println("正在返回,请稍等");
                            Thread.sleep(500);
                            System.out.println("---------------");
                            break;
                        }
                        Dish dish = listDish.get(id - 1);
                        listDish2.add(dish);
                        System.out.println("您点了" + dish.name + "菜品");
                        Thread.sleep(500);
                        System.out.println("---------------");
                    }
                    break;
                case 2:
                    //展示用户点的菜单
                    showPersonDish();
                    String anInt = scanner.next();
                    if (anInt!=null) {
                        break ;
                    }
                    break;
                case 3:
                    //用户结账
                    check();
                    return;
                case 4:
                    System.out.println("欢迎下次光临");
                    break X1;
            }
        }
    }


    //用户结账
    private static void check() {
        Double num=0.0;
        for (int i = 0; i < listDish2.size(); i++) {
            Dish dish = listDish2.get(i);
            Double price = dish.price;
            num+=price;
        }
        System.out.println("已结账,欢迎下次光临");
        System.out.println("您本次共消费"+num);
    }

    //展示用户点的菜单
    private static void showPersonDish() {
        System.out.println("您已点的菜品如下");
        for (int i = 0; i < listDish2.size(); i++) {
            Dish dish = listDish2.get(i);
            System.out.println(dish.id + "     " + dish.name + "    " + dish.price);
        }
        System.out.println("按任意键返回上一级");
    }

    //展示菜单给用户
    private static void showMenuDish() throws InterruptedException {
        System.out.println("欢迎来到点菜页面,请点击下面加号选择菜品");
        for (int i = 0; i < listDish.size(); i++) {
            Dish dish = listDish.get(i);
            System.out.println(dish.id + "     " + dish.name + "    " + dish.price);
        }
        System.out.println("按0返回上一级");
    }

    public static void showMenu() {
        System.out.println("---主菜单---");
        System.out.println("菜单" + "        " + 1);
        System.out.println("已点" + "        " + 2);
        System.out.println("结账" + "        " + 3);
        System.out.println("退出" + "        " + 4);
        System.out.println("请选择");

    }

    public static void initDish() {
        listDish.add(new Dish(1, "鱼肉", 9.99));
        listDish.add(new Dish(2, "鸡肉", 15.99));
        listDish.add(new Dish(3, "牛肉", 39.99));
        listDish.add(new Dish(4, "羊肉", 49.99));
        listDish.add(new Dish(5, "猪肉", 19.99));
    }
}
